From bee3d8eb125b26b497f7001e2d23e34aebd36752 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Wed, 24 Aug 2005 15:09:55 +0000 Subject: [PATCH] s/PixelFormat/Format/g --- ChangeLog | 47 ++++++++ babl/babl-classes.c | 6 +- babl/babl-classes.h | 18 ++-- babl/babl-component.c | 2 +- babl/babl-conversion.c | 12 +-- babl/babl-db.h | 9 ++ babl/babl-fish.c | 84 +++++++++++---- babl/babl-fish.h | 8 +- babl/babl-format.c | 54 +++++----- babl/babl-format.h | 6 +- babl/babl-ids.h | 62 ++++++----- babl/babl-image.c | 19 ++-- babl/babl-image.h | 2 +- babl/babl-internal.c | 6 +- babl/babl-internal.h | 2 +- babl/babl-introspect.c | 22 ++-- babl/babl-model.c | 6 +- babl/babl-model.h | 4 +- babl/babl-pixel-format.c | 54 +++++----- babl/babl-pixel-format.h | 6 +- babl/babl-sanity.c | 42 +++++--- babl/babl-sanity.h | 2 +- babl/babl-type.c | 33 +++++- babl/babl.c | 4 +- babl/babl.h | 1 - babl/base/model-cmyk.c | 6 +- babl/base/model-gray.c | 14 +-- babl/base/model-lab.c | 89 ++++++++++------ babl/base/model-rgb.c | 31 +++--- babl/base/model-ycbcr.c | 75 +++++++------ babl/base/type-u16.c | 129 ++++++++++++++++++++++ babl/base/type-u8.c | 207 +++++++++++++++++++++++++++++++----- tests/Makefile.am | 4 + tests/babl-html-dump.c | 34 +++--- tests/babl_class_name.c | 6 +- tests/float_to_u8.c | 6 +- tests/grayscale_to_rgb.c | 6 +- tests/rgb_to_lab_to_rgb.c | 14 +-- tests/rgb_to_ycbcr.c | 8 +- tests/rgb_to_ycbcr_to_rgb.c | 14 +-- tests/srgb_to_lab_u8.c | 78 ++++++++++++++ tests/u8_to_float.c | 6 +- 42 files changed, 897 insertions(+), 341 deletions(-) create mode 100644 tests/srgb_to_lab_u8.c diff --git a/ChangeLog b/ChangeLog index e6e92d9..d21ffb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2005-08-24 Øyvind KolÃ¥s + + * babl/babl-classes.c, + * babl/babl-classes.h, + * babl/babl-component.c, + * babl/babl-conversion.c, + * babl/babl-db.h, + * babl/babl-fish.c, + * babl/babl-fish.h, + * babl/babl-image.c, + * babl/babl-image.h, + * babl/babl-internal.h, + * babl/babl-introspect.c, + * babl/babl-model.c, + * babl/babl-model.h, + * babl/babl-pixel-format.c, + * babl/babl-pixel-format.h, + * babl/babl-sanity.c, + * babl/babl-sanity.h, + * babl/babl-type.c, + * babl/babl.c, + * babl/babl.h, + * babl/base/model-cmyk.c, + * babl/base/model-gray.c, + * babl/base/model-lab.c, + * babl/base/model-rgb.c, + * babl/base/model-ycbcr.c, + * tests/Makefile.am, + * tests/babl-html-dump.c, + * tests/babl_class_name.c, + * tests/float_to_u8.c, + * tests/grayscale_to_rgb.c, + * tests/rgb_to_lab_to_rgb.c, + * tests/rgb_to_ycbcr.c, + * tests/rgb_to_ycbcr_to_rgb.c, + * tests/u8_to_float.c: s/PixelFormat/Format/ (etc in other cases), + Made BablFish be more polymorphic (accept + format names as well as BablFormats). + * babl/babl-ids.h: reorganized, some renames. + + * tests/srgb_to_lab_u8.c: new test for 8bit CIE Lab format (reference + data not correct yet). + + * babl/base/type-u16.c, + * babl/base/type-u8.c: Added CIE fixed point data types. + + 2005-08-24 Øyvind KolÃ¥s * docs/babl.css: Added code highlighting classes. diff --git a/babl/babl-classes.c b/babl/babl-classes.c index 8f2376d..479ac68 100644 --- a/babl/babl-classes.c +++ b/babl/babl-classes.c @@ -28,13 +28,13 @@ static const char *class_names[] = "BablSampling", "BablComponent", "BablModel", - "BablPixelFormat", + "BablFormat", "BablConversion", "BablConversionType", "BablConversionTypePlanar", "BablConversionModelPlanar", - "BablConversionPixelFormat", - "BablConversionPixelFormatPlanar", + "BablConversionFormat", + "BablConversionFormatPlanar", "BablFish", "BablFishReference", "BablImage", diff --git a/babl/babl-classes.h b/babl/babl-classes.h index 8bd024d..390a270 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -20,12 +20,12 @@ #ifndef _BABL_CLASSES_H #define _BABL_CLASSES_H -/* Type and PixelFormat */ +/* Type and Format */ typedef void (*BablFuncLinear) (void *src, void *dst, int n); -/* TypePlanar, ModelPlanar and PixelFormatPlanar */ +/* TypePlanar, ModelPlanar and FormatPlanar */ typedef void (*BablFuncPlanar) (int src_bands, void *src[], int src_pitch[], @@ -60,14 +60,14 @@ typedef enum { BABL_SAMPLING, BABL_COMPONENT, BABL_MODEL, - BABL_PIXEL_FORMAT, + BABL_FORMAT, BABL_CONVERSION, BABL_CONVERSION_TYPE, BABL_CONVERSION_TYPE_PLANAR, BABL_CONVERSION_MODEL_PLANAR, - BABL_CONVERSION_PIXEL_FORMAT, - BABL_CONVERSION_PIXEL_FORMAT_PLANAR, + BABL_CONVERSION_FORMAT, + BABL_CONVERSION_FORMAT_PLANAR, BABL_FISH, BABL_FISH_REFERENCE, @@ -124,12 +124,12 @@ typedef struct typedef struct { BablConversion conversion; -} BablConversionPixelFormat; +} BablConversionFormat; typedef struct { BablConversion conversion; -} BablConversionPixelFormatPlanar; +} BablConversionFormatPlanar; typedef struct { @@ -199,7 +199,7 @@ typedef struct BablComponent **component; BablType **type; BablSampling **sampling; -} BablPixelFormat; +} BablFormat; typedef struct { @@ -251,7 +251,7 @@ typedef union BablSampling sampling; BablComponent component; BablModel model; - BablPixelFormat pixel_format; + BablFormat format; BablConversion conversion; BablFish fish; BablFishReference reference_fish; diff --git a/babl/babl-component.c b/babl/babl-component.c index 6817bdd..6c86eb4 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -108,7 +108,7 @@ babl_component_new (const char *name, else { - babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'", + babl_log ("%s(): unhandled parameter '%s' for format '%s'", __FUNCTION__, arg, name); exit (-1); } diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index 0c5ccd5..bc9a69e 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -85,17 +85,17 @@ conversion_new (const char *name, __FUNCTION__); } break; - case BABL_PIXEL_FORMAT: + case BABL_FORMAT: if (linear) { - babl = babl_calloc (sizeof (BablConversionPixelFormat), 1); - babl->class_type = BABL_CONVERSION_PIXEL_FORMAT; + babl = babl_calloc (sizeof (BablConversionFormat), 1); + babl->class_type = BABL_CONVERSION_FORMAT; babl->conversion.function.linear = linear; } else if (planar) { - babl = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1); - babl->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR; + babl = babl_calloc (sizeof (BablConversionFormatPlanar), 1); + babl->class_type = BABL_CONVERSION_FORMAT_PLANAR; babl->conversion.function.planar = planar; } else if (planar_bit) @@ -208,7 +208,7 @@ babl_conversion_new (const char *name, } else { - babl_log ("%s(): unhandled parameter '%s' for pixel_format '%s'", + babl_log ("%s(): unhandled parameter '%s' for format '%s'", __FUNCTION__, arg, name); exit (-1); } diff --git a/babl/babl-db.h b/babl/babl-db.h index f0b4abe..270634d 100644 --- a/babl/babl-db.h +++ b/babl/babl-db.h @@ -38,6 +38,15 @@ #define DB_INCREMENT_SIZE 16 #endif +static inline int hash (char *str) +{ + int ret = 0; + int i = 1; + + while (*str) + ret = (ret + ( i++ * (*str ++ & 31 ))) % 199; + return ret; +} /* file scope variables, for this .c file's database */ static int db_size = 0; diff --git a/babl/babl-fish.c b/babl/babl-fish.c index 678af6a..b349f27 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -124,9 +124,9 @@ babl_fish_reference_new (Babl *source, assert (BABL_IS_BABL (source)); assert (BABL_IS_BABL (destination)); - assert (source->class_type == BABL_PIXEL_FORMAT || + assert (source->class_type == BABL_FORMAT || source->class_type == BABL_MODEL); - assert (destination->class_type == BABL_PIXEL_FORMAT || + assert (destination->class_type == BABL_FORMAT || destination->class_type == BABL_MODEL); babl = babl_calloc (sizeof (BablFishReference), 1); @@ -136,53 +136,54 @@ babl_fish_reference_new (Babl *source, babl->fish.source = (union Babl*)source; babl->fish.destination = (union Babl*)destination; - if (source->class_type == BABL_PIXEL_FORMAT) + if (source->class_type == BABL_FORMAT) { babl->reference_fish.type_to_double = babl_conversion_find ( - source->pixel_format.type[0], + source->format.type[0], babl_type_id (BABL_DOUBLE) ); babl->reference_fish.model_to_rgba = babl_conversion_find ( - source->pixel_format.model, + source->format.model, babl_model_id (BABL_RGBA) ); babl->reference_fish.rgba_to_model = babl_conversion_find ( babl_model_id (BABL_RGBA), - destination->pixel_format.model + destination->format.model ); babl->reference_fish.double_to_type = babl_conversion_find ( babl_type_id (BABL_DOUBLE), - destination->pixel_format.type[0] + destination->format.type[0] ); } else if (source->class_type == BABL_MODEL) { babl->reference_fish.type_to_double = NULL; + babl_log ("EEEEEEEEEEEEEEEEEEEEK!%s","!!!!"); babl->reference_fish.model_to_rgba = babl_conversion_find ( - source->pixel_format.model, + source->format.model, babl_model_id (BABL_RGBA) ); babl->reference_fish.rgba_to_model = babl_conversion_find ( babl_model_id (BABL_RGBA), - destination->pixel_format.model + destination->format.model ); babl->reference_fish.double_to_type = babl_conversion_find ( babl_type_id (BABL_DOUBLE), - destination->pixel_format.type[0] + destination->format.type[0] ); } @@ -209,10 +210,48 @@ babl_fish_reference_new (Babl *source, } Babl * -babl_fish (Babl *source, - Babl *destination) +babl_fish (void *source, + void *destination) { - return babl_fish_reference_new (source, destination); + Babl *source_format = NULL; + Babl *destination_format = NULL; + + assert (source); + assert (destination); + + if (BABL_IS_BABL (source)) + { + source_format = source; + } + + if (!source_format) + { + source_format = babl_format ((char*)source); + } + + if (!source_format) + { + babl_log ("%s(%p, %p) source format invalid", + __FUNCTION__, source, destination); + } + + if (BABL_IS_BABL (destination)) + { + destination_format = destination; + } + + if (!destination_format) + { + destination_format = babl_format ((char*)destination); + } + + if (!destination_format) + { + babl_log ("%s(%p, %p) destination format invalid", + __FUNCTION__, source, destination); + } + + return babl_fish_reference_new (source_format, destination_format); } void *fooA; @@ -221,11 +260,14 @@ void *fooC; #define BABL_MAX_BANDS 32 +/* should perhaps have been babl_fish_process, but the public api + * is shorther and makes sense for the API + */ int -babl_fish_process (Babl *babl, - void *source, - void *destination, - int n) +babl_process (Babl *babl, + void *source, + void *destination, + int n) { Babl *imageA; Babl *imageB; @@ -253,11 +295,11 @@ babl_fish_process (Babl *babl, babl_conversion_process (babl->reference_fish.type_to_double, source, fooA, - n * BABL(babl->fish.source)->pixel_format.bands); + n * BABL(babl->fish.source)->format.bands); /* calculate planar representation of fooA, and fooB */ - imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> pixel_format.model)); + imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> format.model)); imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA)); /* transform fooA into fooB fooB is rgba double */ @@ -274,7 +316,7 @@ babl_fish_process (Babl *babl, imageB = babl_image_new_from_linear ( fooB, babl_model_id (BABL_RGBA)); imageC = babl_image_new_from_linear ( - fooA, BABL(BABL((babl->fish.destination))->pixel_format.model)); + fooA, BABL(BABL((babl->fish.destination))->format.model)); babl_conversion_process (babl->reference_fish.rgba_to_model, imageB, imageC, @@ -283,7 +325,7 @@ babl_fish_process (Babl *babl, /* working directly on linear buffers */ babl_conversion_process (babl->reference_fish.double_to_type, fooA, destination, - n * BABL(babl->fish.destination)->pixel_format.bands); + n * BABL(babl->fish.destination)->format.bands); babl_free (imageB); babl_free (imageC); diff --git a/babl/babl-fish.h b/babl/babl-fish.h index ad5235f..5bb2553 100644 --- a/babl/babl-fish.h +++ b/babl/babl-fish.h @@ -25,16 +25,16 @@ BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_fish) /** create a new BablFish capable of translating between the pixel - * formats given in source and destination. (use babl_pixel_format (string)) + * formats given in source and destination. (use babl_format (string)) */ -Babl * babl_fish (Babl *source, - Babl *destination); +Babl * babl_fish (void *source, + void *destination); /* Transform n pixels from source into destination, * source and destination can be pointers to linear buffers * (or at a later stage of babl development BablImages) */ -int babl_fish_process (Babl *babl_fish, +int babl_process (Babl *babl_fish, void *source, void *destination, int n); diff --git a/babl/babl-format.c b/babl/babl-format.c index d10fb5a..1619a81 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -29,18 +29,18 @@ #define BABL_MAX_BANDS 32 static int -each_babl_pixel_format_destroy (Babl *babl, +each_babl_format_destroy (Babl *babl, void *data) { - babl_free (babl->pixel_format.from); - babl_free (babl->pixel_format.to); + babl_free (babl->format.from); + babl_free (babl->format.to); babl_free (babl); return 0; /* continue iterating */ } static Babl * -pixel_format_new (const char *name, +format_new (const char *name, int id, int planar, int bands, @@ -53,7 +53,7 @@ pixel_format_new (const char *name, int band; /* allocate all memory in one chunk */ - babl = babl_calloc (sizeof (BablPixelFormat) + + babl = babl_calloc (sizeof (BablFormat) + strlen (name) + 1 + sizeof (BablComponent*) * (bands+1) + sizeof (BablSampling*) * (bands+1) + @@ -61,34 +61,34 @@ pixel_format_new (const char *name, sizeof (int) * (bands+1) + sizeof (int) * (bands+1),1); - babl->pixel_format.component = ((void *)babl) + sizeof (BablPixelFormat); - babl->pixel_format.type = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1); - babl->pixel_format.sampling = ((void *)babl->pixel_format.type) + sizeof (BablType*) * (bands+1); - babl->instance.name = ((void *)babl->pixel_format.sampling) + sizeof (BablSampling*) * (bands+1); + babl->format.component = ((void *)babl) + sizeof (BablFormat); + babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (bands+1); + babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (bands+1); + babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (bands+1); - babl->class_type = BABL_PIXEL_FORMAT; + babl->class_type = BABL_FORMAT; babl->instance.id = id; strcpy (babl->instance.name, name); - babl->pixel_format.model = model; - babl->pixel_format.bands = bands; - babl->pixel_format.planar = planar; + babl->format.model = model; + babl->format.bands = bands; + babl->format.planar = planar; for (band=0; band < bands; band++) { - babl->pixel_format.component[band] = component[band]; - babl->pixel_format.type[band] = type[band]; - babl->pixel_format.sampling[band] = sampling[band]; + babl->format.component[band] = component[band]; + babl->format.type[band] = type[band]; + babl->format.sampling[band] = sampling[band]; } - babl->pixel_format.component[band] = NULL; - babl->pixel_format.type[band] = NULL; - babl->pixel_format.sampling[band] = NULL; + babl->format.component[band] = NULL; + babl->format.type[band] = NULL; + babl->format.sampling[band] = NULL; return babl; } Babl * -babl_pixel_format_new (const char *name, +babl_format_new (const char *name, ...) { va_list varg; @@ -153,13 +153,13 @@ babl_pixel_format_new (const char *name, model = (BablModel*)arg; break; case BABL_INSTANCE: - case BABL_PIXEL_FORMAT: + case BABL_FORMAT: case BABL_CONVERSION: case BABL_CONVERSION_TYPE: case BABL_CONVERSION_TYPE_PLANAR: case BABL_CONVERSION_MODEL_PLANAR: - case BABL_CONVERSION_PIXEL_FORMAT: - case BABL_CONVERSION_PIXEL_FORMAT_PLANAR: + case BABL_CONVERSION_FORMAT: + case BABL_CONVERSION_FORMAT_PLANAR: case BABL_FISH: case BABL_FISH_REFERENCE: case BABL_IMAGE: @@ -188,7 +188,7 @@ babl_pixel_format_new (const char *name, else { - babl_log ("%s: unhandled parameter '%s' for pixel_format '%s'", + babl_log ("%s: unhandled parameter '%s' for format '%s'", __FUNCTION__, arg, name); exit (-1); } @@ -197,7 +197,7 @@ babl_pixel_format_new (const char *name, va_end (varg); - babl = pixel_format_new (name, id, + babl = format_new (name, id, planar, bands, model, component, sampling, type); @@ -208,9 +208,9 @@ babl_pixel_format_new (const char *name, } else { - each_babl_pixel_format_destroy (babl, NULL); + each_babl_format_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE (babl_pixel_format) +BABL_CLASS_TEMPLATE (babl_format) diff --git a/babl/babl-format.h b/babl/babl-format.h index b43d9c4..2a5f879 100644 --- a/babl/babl-format.h +++ b/babl/babl-format.h @@ -17,10 +17,10 @@ * Boston, MA 02111-1307, USA. */ -#ifndef _BABL_PIXEL_FORMAT_H -#define _BABL_PIXEL_FORMAT_H +#ifndef _BABL_FORMAT_H +#define _BABL_FORMAT_H #include "babl-classes.h" -BABL_DEFINE_CLASS (babl_pixel_format) +BABL_DEFINE_CLASS (babl_format) #endif diff --git a/babl/babl-ids.h b/babl/babl-ids.h index 4a882eb..4de9d89 100644 --- a/babl/babl-ids.h +++ b/babl/babl-ids.h @@ -29,7 +29,33 @@ enum { BABL_DOUBLE, BABL_HALF_FLOAT, - BABL_COMPONENT_BASE = 1000, + BABL_U8_LUMA, + BABL_U8_CHROMA, + BABL_U16_CIE_L, + BABL_U16_CIE_AB, + BABL_U8_CIE_L, + BABL_U8_CIE_AB, + + BABL_MODEL_BASE = 1000, + BABL_RGB, + BABL_RGBA, + BABL_RGB_GAMMA_2_2, + BABL_RGBA_GAMMA_2_2, + BABL_RGBA_PREMULTIPLIED, + BABL_GRAY, + BABL_GRAY_ALPHA, + BABL_GRAY_GAMMA_2_2, + BABL_GRAY_GAMMA_2_2_ALPHA, + BABL_GRAY_ALPHA_PREMULTIPLIED, + BABL_YCBCR, + BABL_YCBCR_ALPHA, + BABL_CIE_LAB, + BABL_CIE_LAB_ALPHA, + BABL_CMY, + BABL_CMYK, + BABL_CMYK_ALPHA, + + BABL_COMPONENT_BASE = 10000, BABL_RED, BABL_GREEN, BABL_BLUE, @@ -46,9 +72,9 @@ enum { BABL_X, BABL_Y, BABL_Z, - BABL_LAB_L, - BABL_LAB_A, - BABL_LAB_B, + BABL_CIE_L, + BABL_CIE_A, + BABL_CIE_B, BABL_CB, BABL_CR, BABL_CYAN, @@ -58,40 +84,24 @@ enum { BABL_Z_BUFFER, BABL_PADDING, - BABL_MODEL_BASE = 10000, - BABL_RGB, - BABL_RGBA, - BABL_RGB_GAMMA_2_2, - BABL_RGBA_GAMMA_2_2, - BABL_RGBA_PREMULTIPLIED, - BABL_GRAY, - BABL_GRAY_ALPHA, - BABL_GRAY_GAMMA_2_2, - BABL_GRAY_GAMMA_2_2_ALPHA, - BABL_GRAY_ALPHA_PREMULTIPLIED, - BABL_YCBCR, - BABL_YCBCR_ALPHA, - BABL_LAB, - BABL_LAB_ALPHA, - BABL_CMY, - BABL_CMYK, - BABL_CMYK_ALPHA, - BABL_PIXEL_FORMAT_BASE = 100000, + BABL_FORMAT_BASE = 100000, BABL_SRGB, BABL_SRGBA, BABL_RGB_FLOAT, BABL_RGBA_FLOAT, BABL_RGBA_DOUBLE, BABL_LAB_FLOAT, - BABL_YUV420, + BABL_LAB_U16, + BABL_LAB_U8, BABL_RGB_U8, BABL_RGBA_U8, BABL_RGBA_U16, BABL_CMYK_FLOAT, BABL_CMYK_ALPHA_FLOAT, - BABL_YUV411, - BABL_YUV422, + BABL_YCBCR411, + BABL_YCBCR422, + BABL_YCBCR420, BABL_PIXEL_USER_BASE, }; diff --git a/babl/babl-image.c b/babl/babl-image.c index 831925c..d80bc7f 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -85,23 +85,23 @@ babl_image_new_from_linear (void *buffer, int calc_pitch=0; assert (format); - assert (format->class_type == BABL_PIXEL_FORMAT || + assert (format->class_type == BABL_FORMAT || format->class_type == BABL_MODEL); switch (format->class_type) { - case BABL_PIXEL_FORMAT: - for (band=0; band < format->pixel_format.bands; band++) + case BABL_FORMAT: + for (band=0; band < format->format.bands; band++) { - BablType *type = format->pixel_format.type[band]; + BablType *type = format->format.type[band]; calc_pitch += (type->bits / 8); } - for (band=0; band < format->pixel_format.bands; band++) + for (band=0; band < format->format.bands; band++) { - BablType *type = format->pixel_format.type[band]; + BablType *type = format->format.type[band]; - component[band] = format->pixel_format.component[band]; + component[band] = format->format.component[band]; data[band] = buffer + offset; pitch[band] = calc_pitch; stride[band] = 0; @@ -172,9 +172,10 @@ babl_image_new (void *first, } else { - new_component = (BablComponent*)babl_component (arg); + new_component = (BablComponent*) babl_component (arg); } + /* FIXME: add error checking */ component [bands] = new_component; data [bands] = va_arg (varg, void*); pitch [bands] = va_arg (varg, int); @@ -183,7 +184,7 @@ babl_image_new (void *first, if (bands>=BABL_MAX_BANDS) { - babl_log ("%s(): maximum number of bands (%i) exceeded for BablImage", + babl_log ("%s(): maximum number of bands (%i) exceeded", __FUNCTION__, BABL_MAX_BANDS); } diff --git a/babl/babl-image.h b/babl/babl-image.h index 6115750..c3666f8 100644 --- a/babl/babl-image.h +++ b/babl/babl-image.h @@ -30,7 +30,7 @@ Babl * babl_image_new (void *first_component, ...); -/* create a new BablImage based on a packed BablPixelFormat (or BablModel which +/* create a new BablImage based on a packed BablFormat (or BablModel which * is a virtual pixelformat based on the BablModel using only doubles in the * order they are listed in the model. */ diff --git a/babl/babl-internal.c b/babl/babl-internal.c index 8f2376d..479ac68 100644 --- a/babl/babl-internal.c +++ b/babl/babl-internal.c @@ -28,13 +28,13 @@ static const char *class_names[] = "BablSampling", "BablComponent", "BablModel", - "BablPixelFormat", + "BablFormat", "BablConversion", "BablConversionType", "BablConversionTypePlanar", "BablConversionModelPlanar", - "BablConversionPixelFormat", - "BablConversionPixelFormatPlanar", + "BablConversionFormat", + "BablConversionFormatPlanar", "BablFish", "BablFishReference", "BablImage", diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 8607497..b5e3fc5 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -55,7 +55,7 @@ type_name##_id (int id) \ babl = db_exist (id, NULL); \ if (!babl) \ { \ - babl_log ("%s(\"%i\"): not found", __FUNCTION__, id); \ + babl_log ("%s(%i): not found", __FUNCTION__, id); \ } \ return babl; \ } diff --git a/babl/babl-introspect.c b/babl/babl-introspect.c index 001a41d..b20bd86 100644 --- a/babl/babl-introspect.c +++ b/babl/babl-introspect.c @@ -23,7 +23,7 @@ static void sampling_introspect (Babl *babl); static void model_introspect (Babl *babl); static void type_introspect (Babl *babl); -static void pixel_format_introspect (Babl *babl); +static void format_introspect (Babl *babl); static int each_introspect (Babl *babl, void *user_data); @@ -47,7 +47,7 @@ babl_introspect (void) babl_model_each (each_introspect, NULL); babl_log ("%s",""); babl_log ("Pixel formats:%s", ""); - babl_pixel_format_each (each_introspect, NULL); + babl_format_each (each_introspect, NULL); babl_log ("%s",""); babl_log ("conversions:%s", ""); babl_conversion_each (each_introspect, NULL); @@ -135,18 +135,18 @@ sampling_introspect (Babl *babl) static void -pixel_format_introspect (Babl *babl) +format_introspect (Babl *babl) { int i; - babl_log ("\t\tplanar=%i", babl->pixel_format.planar); - babl_log ("\t\tbands=%i", babl->pixel_format.bands); + babl_log ("\t\tplanar=%i", babl->format.planar); + babl_log ("\t\tbands=%i", babl->format.bands); - for (i=0; i< babl->pixel_format.bands; i++) + for (i=0; i< babl->format.bands; i++) { babl_log ("\t\tband[%i] type='%s' component='%s' sampling='%s'", - i, babl->pixel_format.type[i]->instance.name, - babl->pixel_format.component[i]->instance.name, - babl->pixel_format.sampling[i]->instance.name); + i, babl->format.type[i]->instance.name, + babl->format.component[i]->instance.name, + babl->format.sampling[i]->instance.name); } } @@ -171,8 +171,8 @@ each_introspect (Babl *babl, model_introspect (babl); item_conversions_introspect (babl); break; - case BABL_PIXEL_FORMAT: - pixel_format_introspect (babl); + case BABL_FORMAT: + format_introspect (babl); item_conversions_introspect (babl); break; case BABL_SAMPLING: diff --git a/babl/babl-model.c b/babl/babl-model.c index 6b44cd7..2338b0c 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -108,15 +108,15 @@ babl_model_new (const char *name, case BABL_TYPE: case BABL_SAMPLING: case BABL_INSTANCE: - case BABL_PIXEL_FORMAT: + case BABL_FORMAT: case BABL_CONVERSION: case BABL_CONVERSION_TYPE: case BABL_CONVERSION_TYPE_PLANAR: case BABL_CONVERSION_MODEL_PLANAR: - case BABL_CONVERSION_PIXEL_FORMAT: - case BABL_CONVERSION_PIXEL_FORMAT_PLANAR: + case BABL_CONVERSION_FORMAT: + case BABL_CONVERSION_FORMAT_PLANAR: case BABL_FISH: case BABL_FISH_REFERENCE: case BABL_IMAGE: diff --git a/babl/babl-model.h b/babl/babl-model.h index d31cbe5..12df09b 100644 --- a/babl/babl-model.h +++ b/babl/babl-model.h @@ -17,8 +17,8 @@ * Boston, MA 02111-1307, USA. */ -#ifndef _BABL_pixel_format_H -#define _BABL_pixel_format_H +#ifndef _BABL_format_H +#define _BABL_format_H #include "babl-classes.h" BABL_DEFINE_CLASS (babl_model) diff --git a/babl/babl-pixel-format.c b/babl/babl-pixel-format.c index d10fb5a..1619a81 100644 --- a/babl/babl-pixel-format.c +++ b/babl/babl-pixel-format.c @@ -29,18 +29,18 @@ #define BABL_MAX_BANDS 32 static int -each_babl_pixel_format_destroy (Babl *babl, +each_babl_format_destroy (Babl *babl, void *data) { - babl_free (babl->pixel_format.from); - babl_free (babl->pixel_format.to); + babl_free (babl->format.from); + babl_free (babl->format.to); babl_free (babl); return 0; /* continue iterating */ } static Babl * -pixel_format_new (const char *name, +format_new (const char *name, int id, int planar, int bands, @@ -53,7 +53,7 @@ pixel_format_new (const char *name, int band; /* allocate all memory in one chunk */ - babl = babl_calloc (sizeof (BablPixelFormat) + + babl = babl_calloc (sizeof (BablFormat) + strlen (name) + 1 + sizeof (BablComponent*) * (bands+1) + sizeof (BablSampling*) * (bands+1) + @@ -61,34 +61,34 @@ pixel_format_new (const char *name, sizeof (int) * (bands+1) + sizeof (int) * (bands+1),1); - babl->pixel_format.component = ((void *)babl) + sizeof (BablPixelFormat); - babl->pixel_format.type = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1); - babl->pixel_format.sampling = ((void *)babl->pixel_format.type) + sizeof (BablType*) * (bands+1); - babl->instance.name = ((void *)babl->pixel_format.sampling) + sizeof (BablSampling*) * (bands+1); + babl->format.component = ((void *)babl) + sizeof (BablFormat); + babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (bands+1); + babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (bands+1); + babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (bands+1); - babl->class_type = BABL_PIXEL_FORMAT; + babl->class_type = BABL_FORMAT; babl->instance.id = id; strcpy (babl->instance.name, name); - babl->pixel_format.model = model; - babl->pixel_format.bands = bands; - babl->pixel_format.planar = planar; + babl->format.model = model; + babl->format.bands = bands; + babl->format.planar = planar; for (band=0; band < bands; band++) { - babl->pixel_format.component[band] = component[band]; - babl->pixel_format.type[band] = type[band]; - babl->pixel_format.sampling[band] = sampling[band]; + babl->format.component[band] = component[band]; + babl->format.type[band] = type[band]; + babl->format.sampling[band] = sampling[band]; } - babl->pixel_format.component[band] = NULL; - babl->pixel_format.type[band] = NULL; - babl->pixel_format.sampling[band] = NULL; + babl->format.component[band] = NULL; + babl->format.type[band] = NULL; + babl->format.sampling[band] = NULL; return babl; } Babl * -babl_pixel_format_new (const char *name, +babl_format_new (const char *name, ...) { va_list varg; @@ -153,13 +153,13 @@ babl_pixel_format_new (const char *name, model = (BablModel*)arg; break; case BABL_INSTANCE: - case BABL_PIXEL_FORMAT: + case BABL_FORMAT: case BABL_CONVERSION: case BABL_CONVERSION_TYPE: case BABL_CONVERSION_TYPE_PLANAR: case BABL_CONVERSION_MODEL_PLANAR: - case BABL_CONVERSION_PIXEL_FORMAT: - case BABL_CONVERSION_PIXEL_FORMAT_PLANAR: + case BABL_CONVERSION_FORMAT: + case BABL_CONVERSION_FORMAT_PLANAR: case BABL_FISH: case BABL_FISH_REFERENCE: case BABL_IMAGE: @@ -188,7 +188,7 @@ babl_pixel_format_new (const char *name, else { - babl_log ("%s: unhandled parameter '%s' for pixel_format '%s'", + babl_log ("%s: unhandled parameter '%s' for format '%s'", __FUNCTION__, arg, name); exit (-1); } @@ -197,7 +197,7 @@ babl_pixel_format_new (const char *name, va_end (varg); - babl = pixel_format_new (name, id, + babl = format_new (name, id, planar, bands, model, component, sampling, type); @@ -208,9 +208,9 @@ babl_pixel_format_new (const char *name, } else { - each_babl_pixel_format_destroy (babl, NULL); + each_babl_format_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE (babl_pixel_format) +BABL_CLASS_TEMPLATE (babl_format) diff --git a/babl/babl-pixel-format.h b/babl/babl-pixel-format.h index b43d9c4..2a5f879 100644 --- a/babl/babl-pixel-format.h +++ b/babl/babl-pixel-format.h @@ -17,10 +17,10 @@ * Boston, MA 02111-1307, USA. */ -#ifndef _BABL_PIXEL_FORMAT_H -#define _BABL_PIXEL_FORMAT_H +#ifndef _BABL_FORMAT_H +#define _BABL_FORMAT_H #include "babl-classes.h" -BABL_DEFINE_CLASS (babl_pixel_format) +BABL_DEFINE_CLASS (babl_format) #endif diff --git a/babl/babl-sanity.c b/babl/babl-sanity.c index a861fff..88d9aa2 100644 --- a/babl/babl-sanity.c +++ b/babl/babl-sanity.c @@ -19,6 +19,8 @@ #include "babl.h" #include "babl-internal.h" + +static int OK; static int foo (Babl *babl, @@ -56,8 +58,11 @@ type_sanity (Babl *babl, } } if (!ok) - babl_log ("lack of sanity! type '%s' has no conversion to double", - babl->instance.name); + { + OK = 0; + babl_log ("lack of sanity! type '%s' has no conversion to double", + babl->instance.name); + } ok = 0; @@ -76,8 +81,11 @@ type_sanity (Babl *babl, } } if (!ok) - babl_log ("lack of sanity! type '%s' has no conversion from double", - babl->instance.name); + { + OK=0; + babl_log ("lack of sanity! type '%s' has no conversion from double", + babl->instance.name); + } return 0; } @@ -108,8 +116,11 @@ model_sanity (Babl *babl, } } if (!ok) - babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'", - babl->instance.name); + { + OK=0; + babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'", + babl->instance.name); + } ok = 0; @@ -128,8 +139,11 @@ model_sanity (Babl *babl, } } if (!ok) - babl_log ("lack of sanity! model '%s' has no conversion from 'rgba'", - babl->instance.name); + { + babl_log ("lack of sanity! model '%s' has no conversion from 'rgba'", + babl->instance.name); + OK=0; + } return 0; } @@ -140,29 +154,31 @@ id_sanity (Babl *babl, { if (0 == babl->instance.id) { + OK=0; babl_log ("%s\t'%s' has id==0", babl_class_name (babl->class_type), babl->instance.name); } return 0; } -void +int babl_sanity (void) { + OK=1; + babl_type_each (id_sanity, NULL); babl_component_each (id_sanity, NULL); babl_model_each (id_sanity, NULL); - babl_pixel_format_each (id_sanity, NULL); + babl_format_each (id_sanity, NULL); babl_type_each (type_sanity, NULL); babl_sampling_each (foo, NULL); babl_component_each (foo, NULL); babl_model_each (model_sanity, NULL); - babl_pixel_format_each (foo, NULL); + babl_format_each (foo, NULL); babl_conversion_each (foo, NULL); - - + return OK; } static Babl *babl_conversion_source (Babl *babl) diff --git a/babl/babl-sanity.h b/babl/babl-sanity.h index 0f41067..18c978c 100644 --- a/babl/babl-sanity.h +++ b/babl/babl-sanity.h @@ -20,6 +20,6 @@ #ifndef _BABL_SANITY_H #define _BABL_SANITY_H -void babl_sanity (void); +int babl_sanity (void); #endif diff --git a/babl/babl-type.c b/babl/babl-type.c index 0412cfa..362fe58 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -62,8 +62,13 @@ babl_type_new (const char *name, { va_list varg; Babl *babl; - int id = 0; - int bits = 0; + int id = 0; + int is_integer = 0; + int bits = 0; + long min = 0; + long max = 255; + double min_val = 0.0; + double max_val = 0.0; const char *arg=name; @@ -91,11 +96,33 @@ babl_type_new (const char *name, else if (!strcmp (arg, "bits")) { bits = va_arg (varg, int); + min = 0; + max = 1< max_val) + u16val = max; + else + u16val = (dval-min_val) / (max_val-min_val) * (max-min) + min; + + *(unsigned short *) dst = u16val; + dst += 2; + src += 8; + } +} + +static inline void +convert_u16_double_scaled (double min_val, + double max_val, + unsigned short min, + unsigned short max, + void *src, + void *dst, + int n) +{ + while (n--) + { + int u16val = *(unsigned short*) src; + double dval; + + if (u16val < min) + dval = min_val; + else if (u16val > max) + dval = max_val; + else + dval = (u16val-min) / (double)(max-min) * (max_val-min_val) + min_val; + + (*(double *) dst) = dval; + dst += 8; + src += 1; + } +} + + + static void convert_double_u16 (void *src, void *dst, @@ -57,6 +114,24 @@ convert_u16_double (void *src, } } + +/* source ICC.1:2004-10 */ + +static void convert_double_u16_l (void *src, void *dst, int n){ + convert_double_u16_scaled (0.0, 100.0, 0x00, 0xffff, src, dst, n); +} +static void convert_u16_l_double (void *src, void *dst, int n){ + convert_u16_double_scaled (0.0, 100.0, 0x00, 0xffff, src, dst, n); +} + +static void convert_double_u16_ab (void *src, void *dst, int n){ + convert_double_u16_scaled (-128.0, 127.0, 0x00, 0xffff, src, dst, n); +} +static void convert_u16_ab_double (void *src, void *dst, int n){ + convert_u16_double_scaled (-128.0, 127.0, 0x00, 0xffff, src, dst, n); +} + + void babl_base_type_u16 (void) { @@ -66,6 +141,29 @@ babl_base_type_u16 (void) "bits", 16, NULL); + babl_type_new ( + "u16-CIE-L", + "id", BABL_U16_CIE_L, + "integer", + "unsigned", + "bits", 16, + "min_val", 0.0, + "max_val", 100.0, + NULL + ); + + babl_type_new ( + "u16-CIE-ab", + "id", BABL_U16_CIE_AB, + "integer", + "unsigned", + "bits", 16, + "min_val", -50.0, + "max_val", 50.0, + NULL + ); + + babl_conversion_new ( "babl-base: u16 to double", "source", babl_type_id (BABL_U16), @@ -81,4 +179,35 @@ babl_base_type_u16 (void) "linear", convert_double_u16, NULL ); + + + babl_conversion_new ( + "babl-base: u16-CIE-L to double", + "source", babl_type_id (BABL_U16_CIE_L), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u16_l_double, + NULL + ); + babl_conversion_new ( + "babl-base: double to u16-CIE-L", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U16_CIE_L), + "linear", convert_double_u16_l, + NULL + ); + + babl_conversion_new ( + "babl-base: u16-CIE-ab to double", + "source", babl_type_id (BABL_U16_CIE_AB), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u16_ab_double, + NULL + ); + babl_conversion_new ( + "babl-base: double to u16-CIE-ab", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U16_CIE_AB), + "linear", convert_double_u16_ab, + NULL + ); } diff --git a/babl/base/type-u8.c b/babl/base/type-u8.c index b0d8121..03a6830 100644 --- a/babl/base/type-u8.c +++ b/babl/base/type-u8.c @@ -22,42 +22,99 @@ #include "babl.h" -static void -convert_u8_double (void *src, - void *dst, - int n) +static inline void +convert_double_u8_scaled (double min_val, + double max_val, + unsigned char min, + unsigned char max, + void *src, + void *dst, + int n) { while (n--) { - (*(double *) dst) = (*(unsigned char *) src/255.0); - dst += 8; - src += 1; + double dval = *(double *) src; + unsigned char u8val; + + if (dval < min_val) + u8val = min; + else if (dval > max_val) + u8val = max; + else + u8val = (dval-min_val) / (max_val-min_val) * (max-min) + min; + + *(unsigned char *) dst = u8val; + dst += 1; + src += 8; } } -static void -convert_double_u8 (void *src, - void *dst, - int n) +static inline void +convert_u8_double_scaled (double min_val, + double max_val, + unsigned char min, + unsigned char max, + void *src, + void *dst, + int n) { while (n--) { - double dval = *(double *) src; - unsigned char u8val; + int u8val = *(unsigned char *) src; + double dval; - if (dval < 0) - u8val = 0; - else if (dval > 1) - u8val = 255; + if (u8val < min) + dval = min_val; + else if (u8val > max) + dval = max_val; else - u8val = dval*255.0; + dval = (u8val-min) / (double)(max-min) * (max_val-min_val) + min_val; - *(unsigned char *) dst = u8val; - dst += 1; - src += 8; + (*(double *) dst) = dval; + dst += 8; + src += 1; } } + +static void convert_u8_double (void *src, void *dst, int n){ + convert_u8_double_scaled (0.0, 1.0, 0, 255, src, dst, n); +} +static void convert_double_u8 (void *src, void *dst, int n){ + convert_double_u8_scaled (0.0, 1.0, 0, 255, src, dst, n); +} + +static void convert_double_u8_luma (void *src, void *dst, int n){ + convert_double_u8_scaled (0.0, 1.0, 16, 235, src, dst, n); +} +static void convert_u8_luma_double (void *src, void *dst, int n){ + convert_u8_double_scaled (0.0, 1.0, 16, 235, src, dst, n); +} + +static void convert_double_u8_chroma (void *src, void *dst, int n){ + convert_double_u8_scaled (-0.5, 0.5, 16, 240, src, dst, n); +} +static void convert_u8_chroma_double (void *src, void *dst, int n){ + convert_u8_double_scaled (-0.5, 0.5, 16, 240, src, dst, n); +} + +/* source ICC.1:2004-10 */ + +static void convert_double_u8_l (void *src, void *dst, int n){ + convert_double_u8_scaled (0.0, 100.0, 0x00, 0xff, src, dst, n); +} +static void convert_u8_l_double (void *src, void *dst, int n){ + convert_u8_double_scaled (0.0, 100.0, 0x00, 0xff, src, dst, n); +} + +static void convert_double_u8_ab (void *src, void *dst, int n){ + convert_double_u8_scaled (-128.0, 127.0, 0x00, 0xff, src, dst, n); +} +static void convert_u8_ab_double (void *src, void *dst, int n){ + convert_u8_double_scaled (-128.0, 127.0, 0x00, 0xff, src, dst, n); +} + + void babl_base_type_u8 (void) { @@ -67,19 +124,121 @@ babl_base_type_u8 (void) "bits", 8, NULL); + babl_type_new ( + "u8-luma", + "id", BABL_U8_LUMA, + "bits", 8, + NULL + ); + + babl_type_new ( + "u8-chroma", + "id", BABL_U8_CHROMA, + "integer", + "unsigned", + "bits", 8, + "min", (long) 16, + "max", (long)240, + "min_val", -0.5, + "max_val", 0.5, + NULL + ); + + babl_type_new ( + "u8-CIE-L", + "id", BABL_U8_CIE_L, + "integer", + "unsigned", + "bits", 8, + "min_val", 0.0, + "max_val", 100.0, + NULL + ); + + babl_type_new ( + "u8-CIE-ab", + "id", BABL_U8_CIE_AB, + "integer", + "unsigned", + "bits", 8, + "min_val", -50.0, + "max_val", 50.0, + NULL + ); + babl_conversion_new ( "babl-base: u8 to double", "source", babl_type_id (BABL_U8), "destination", babl_type_id (BABL_DOUBLE), - "linear", convert_u8_double, + "linear", convert_u8_double, NULL ); - babl_conversion_new ( "babl-base: double to u8", "source", babl_type_id (BABL_DOUBLE), "destination", babl_type_id (BABL_U8), - "linear", convert_double_u8, + "linear", convert_double_u8, + NULL + ); + + + babl_conversion_new ( + "babl-base: u8-luma to double", + "source", babl_type_id (BABL_U8_LUMA), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u8_luma_double, + NULL + ); + babl_conversion_new ( + "babl-base: double to u8-luma", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U8_LUMA), + "linear", convert_double_u8_luma, + NULL + ); + + babl_conversion_new ( + "babl-base: u8-chroma to double", + "source", babl_type_id (BABL_U8_CHROMA), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u8_chroma_double, + NULL + ); + babl_conversion_new ( + "babl-base: double to u8-chroma", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U8_CHROMA), + "linear", convert_double_u8_chroma, + NULL + ); + + babl_conversion_new ( + "babl-base: u8-CIE-L to double", + "source", babl_type_id (BABL_U8_CIE_L), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u8_l_double, + NULL + ); + babl_conversion_new ( + "babl-base: double to u8-CIE-L", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U8_CIE_L), + "linear", convert_double_u8_l, + NULL + ); + + babl_conversion_new ( + "babl-base: u8-CIE-ab to double", + "source", babl_type_id (BABL_U8_CIE_AB), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u8_ab_double, + NULL + ); + babl_conversion_new ( + "babl-base: double to u8-CIE-ab", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U8_CIE_AB), + "linear", convert_double_u8_ab, NULL ); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 1bc9955..8d9c370 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,15 +5,19 @@ TESTS = \ rgb_to_lab_to_rgb \ rgb_to_ycbcr \ rgb_to_ycbcr_to_rgb \ + srgb_to_lab_u8 \ + sanity \ babl_class_name float_to_u8_SOURCES = float_to_u8.c u8_to_float_SOURCES = u8_to_float.c grayscale_to_rgb_SOURCES = grayscale_to_rgb.c rgb_to_lab_to_rgb_SOURCES = rgb_to_lab_to_rgb.c +srgb_to_lab_u8_SOURCES = srgb_to_lab_u8.c rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c babl_class_name_SOURCES = babl_class_name.c +sanity_SOURCES = sanity.c AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl diff --git a/tests/babl-html-dump.c b/tests/babl-html-dump.c index 573d113..fbf13f1 100644 --- a/tests/babl-html-dump.c +++ b/tests/babl-html-dump.c @@ -22,7 +22,7 @@ static void model_html (Babl *babl); static void type_html (Babl *babl); -static void pixel_format_html (Babl *babl); +static void format_html (Babl *babl); static int each_item (Babl *babl, void *user_data); @@ -41,7 +41,7 @@ main (void) babl_model_each (each_item, NULL); printf (" \n"); printf ("Pixel formatbytes/pixelcolor modelbands \n"); - babl_pixel_format_each (each_item, NULL); + babl_format_each (each_item, NULL); printf ("\n"); babl_destroy (); @@ -63,8 +63,8 @@ each_item (Babl *babl, case BABL_MODEL: model_html (babl); break; - case BABL_PIXEL_FORMAT: - pixel_format_html (babl); + case BABL_FORMAT: + format_html (babl); break; default: break; @@ -95,42 +95,42 @@ type_html (Babl *babl) } static void -pixel_format_html (Babl *babl) +format_html (Babl *babl) { int i; printf (""); { int bytes=0; - for (i=0; i< babl->pixel_format.bands; i++) + for (i=0; i< babl->format.bands; i++) { - bytes += BABL(babl->pixel_format.type[i])->type.bits/8; + bytes += BABL(babl->format.type[i])->type.bits/8; } printf ("%i", bytes); } printf (""); printf (""); - printf ("%s", BABL(babl->pixel_format.model)->instance.name ); + printf ("%s", BABL(babl->format.model)->instance.name ); printf (""); printf (""); - for (i=0; i< babl->pixel_format.bands; i++) + for (i=0; i< babl->format.bands; i++) { printf ("%s %s 
", - BABL(babl->pixel_format.type[i])->instance.name, - BABL(babl->pixel_format.component[i])->instance.name ); + BABL(babl->format.type[i])->instance.name, + BABL(babl->format.component[i])->instance.name ); } printf (""); #if 0 int i; - babl_log ("\t\tplanar=%i", babl->pixel_format.planar); - babl_log ("\t\tbands=%i", babl->pixel_format.bands); + babl_log ("\t\tplanar=%i", babl->format.planar); + babl_log ("\t\tbands=%i", babl->format.bands); - for (i=0; i< babl->pixel_format.bands; i++) + for (i=0; i< babl->format.bands; i++) { babl_log ("\t\tband[%i] type='%s' component='%s' sampling='%s'", - i, babl->pixel_format.type[i]->instance.name, - babl->pixel_format.component[i]->instance.name, - babl->pixel_format.sampling[i]->instance.name); + i, babl->format.type[i]->instance.name, + babl->format.component[i]->instance.name, + babl->format.sampling[i]->instance.name); } #endif } diff --git a/tests/babl_class_name.c b/tests/babl_class_name.c index 643848b..d411518 100644 --- a/tests/babl_class_name.c +++ b/tests/babl_class_name.c @@ -32,13 +32,13 @@ struct {BABL_SAMPLING, "BablSampling"}, {BABL_COMPONENT, "BablComponent"}, {BABL_MODEL, "BablModel"}, - {BABL_PIXEL_FORMAT, "BablPixelFormat"}, + {BABL_FORMAT, "BablFormat"}, {BABL_CONVERSION, "BablConversion"}, {BABL_CONVERSION_TYPE, "BablConversionType"}, {BABL_CONVERSION_TYPE_PLANAR, "BablConversionTypePlanar"}, {BABL_CONVERSION_MODEL_PLANAR, "BablConversionModelPlanar"}, - {BABL_CONVERSION_PIXEL_FORMAT, "BablConversionPixelFormat"}, - {BABL_CONVERSION_PIXEL_FORMAT_PLANAR, "BablConversionPixelFormatPlanar"}, + {BABL_CONVERSION_FORMAT, "BablConversionFormat"}, + {BABL_CONVERSION_FORMAT_PLANAR, "BablConversionFormatPlanar"}, {BABL_FISH, "BablFish"}, {BABL_FISH_REFERENCE, "BablFishReference"}, {BABL_IMAGE, "BablImage"}, diff --git a/tests/float_to_u8.c b/tests/float_to_u8.c index e1b4bd5..29844c2 100644 --- a/tests/float_to_u8.c +++ b/tests/float_to_u8.c @@ -52,14 +52,14 @@ test_float_to_rgb_u8 (void) fish = babl_fish ( - babl_pixel_format_new ( + babl_format_new ( "foo", babl_model ("gray"), babl_type ("float"), babl_component ("Y"), NULL ), - babl_pixel_format_new ( + babl_format_new ( "bar", babl_model ("gray"), babl_type ("u8"), @@ -67,7 +67,7 @@ test_float_to_rgb_u8 (void) NULL )); - babl_fish_process (fish, + babl_process (fish, float_buf, u8_buf, BUFFER_LENGTH); diff --git a/tests/grayscale_to_rgb.c b/tests/grayscale_to_rgb.c index 6d51701..9e9df64 100644 --- a/tests/grayscale_to_rgb.c +++ b/tests/grayscale_to_rgb.c @@ -38,14 +38,14 @@ test (void) fish = babl_fish ( - babl_pixel_format_new ( + babl_format_new ( "foo", babl_model ("gray"), babl_type ("float"), babl_component ("Y"), NULL ), - babl_pixel_format_new ( + babl_format_new ( "bar", babl_model ("rgb"), babl_type ("float"), @@ -56,7 +56,7 @@ test (void) ) ); - babl_fish_process (fish, + babl_process (fish, grayscale_buf, rgb_buf, PIXELS); diff --git a/tests/rgb_to_lab_to_rgb.c b/tests/rgb_to_lab_to_rgb.c index 9c5f477..4394651 100644 --- a/tests/rgb_to_lab_to_rgb.c +++ b/tests/rgb_to_lab_to_rgb.c @@ -75,7 +75,7 @@ test (void) fish = babl_fish ( - babl_pixel_format_new ( + babl_format_new ( "foo", babl_model ("rgb"), babl_type ("float"), @@ -84,7 +84,7 @@ test (void) babl_component ("B"), NULL ), - babl_pixel_format_new ( + babl_format_new ( "bar", babl_model ("CIE Lab"), babl_type ("float"), @@ -95,12 +95,14 @@ test (void) ) ); - babl_fish_process (fish, source_buf, temp_buf, PIXELS); + babl_process (fish, source_buf, temp_buf, PIXELS); - fish = babl_fish (babl_pixel_format ("bar"), - babl_pixel_format ("foo")); + /* this test tests both pixel format creation, and the scope of + * babl_fish()'s polymorphism + */ + fish = babl_fish ("bar","foo"); - babl_fish_process (fish, temp_buf, destination_buf, PIXELS); + babl_process (fish, temp_buf, destination_buf, PIXELS); for (i=0; i +#include "babl.h" +#include "babl-internal.h" + +#define PIXELS 6 +#define TOLERANCE 0 + +unsigned char source_buf [PIXELS*3]= + { 0, 0, 0, + 127, 127, 127, + 255, 255, 255, + 255, 0.0, 0.0, + 0.0, 255, 0.0, + 0.0, 0.0, 255}; + +unsigned char reference_buf [PIXELS*3]= + { 0, 0, 0, + 127, 0, 0, + 255, 255, 255, + 0, 0, 0, + 0, 0, 0, + 0, 0, 0}; + +unsigned char destination_buf [PIXELS*3]; + +int +test (void) +{ + int i; + int OK=1; + + babl_process (babl_fish ("srgb", "cie-lab-u8"), + source_buf, destination_buf, + PIXELS); + + for (i=0; i TOLERANCE) + { + babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i", + i, i,i%3, i,i/3, destination_buf[i], reference_buf[i]); + OK=0; + } + } + if (!OK) + return -1; + return 0; +} + +int +main (int argc, + char **argv) +{ + babl_init (); + if (test()) + return -1; + babl_destroy (); + return 0; +} diff --git a/tests/u8_to_float.c b/tests/u8_to_float.c index 7ffa2cb..e33fb72 100644 --- a/tests/u8_to_float.c +++ b/tests/u8_to_float.c @@ -37,14 +37,14 @@ test (void) fish = babl_fish ( - babl_pixel_format_new ( + babl_format_new ( "foo", babl_model ("gray"), babl_type ("u8"), babl_component ("Y"), NULL ), - babl_pixel_format_new ( + babl_format_new ( "bar", babl_model ("gray"), babl_type ("float"), @@ -52,7 +52,7 @@ test (void) NULL )); - babl_fish_process (fish, + babl_process (fish, u8_buf, float_buf, BUFFER_LENGTH); -- 2.30.2